<?php
 Session_Start () ;
 If (!$_SESSION ["repertoire_config"]) { Header ("Location: ../../") ; }
 Include ($_SESSION ["repertoire_config"]."/garennes.cfg") ;
 Include ($_SESSION ["repertoire_config"]."/init.php") ;
 Include ($_SESSION ["repertoire_config"]."/module_absences.php") ;
 Include ("../include/config.inc") ;
 Include ("../include/absences.cfg") ;
 verif_droits ($droit_courant, $_SESSION ["code"]) ;
 
 //Include ("../../include/var_temp.inc") ;
 
 $requete = var_courante ("requete", 0, Null) ;
 $id_eleve = var_courante ("id_eleve", 0, 0) ;
 $creation = var_courante ("creation", 0, 0) ;
 $date_demande = var_courante ("date_demande", 0, 0) ;
 
 If (IsSet ($requete))
  {
   If ($requete == "VaLiDeR")
    {
     $id = var_courante ("id", 0, 0) ;
     $a1 = var_courante ("a1", 0, 0) ;
     $m1 = var_courante ("m1", 0, 0) ;
     $j1 = var_courante ("j1", 0, 0) ;
     $a2 = var_courante ("a2", 0, 0) ;
     $m2 = var_courante ("m2", 0, 0) ;
     $j2 = var_courante ("j2", 0, 0) ;
     $requete = "" ;
     If ($id > 0)
      {
       // Mise a jour quarantaine
       If (($a1 > 0) And ($m1 > 0) And ($j1 > 0) And ($a2 > 0) And ($m2 > 0) And ($j2 > 0))
        {
         $requete  = "UPDATE abs_quarantaine SET date_debut='".$a1."-".$m1."-".$j1."',date_fin='".$a2."-".$m2."-".$j2."' " ;
         $requete .= "WHERE id_abs_quarantaine='".$id."' LIMIT 1" ;
        }
      }
     Else
      {
       // Nouvelle quarantaine
       $repere1 = var_courante ("repere1", 0, 0) ;
       $repere2 = var_courante ("repere2", 0, 0) ;
       If ($id_eleve > 0)
        {
         $requete  = "INSERT INTO abs_quarantaine (id_abs_quarantaine,eleve,repere1,repere2,date_debut,date_fin) " ;
         $requete .= "VALUES ('','".$id_eleve."','".$repere1."','".$repere2."','".$a1."-".$m1."-".$j1."','".$a2."-".$m2."-".$j2."')" ;
        }
      }
     If ($requete != "") { $ok = SQL_commande ($requete, $id_sql) ; }
     Echo "<html><body><script type=\"text/javascript\">" ;
     If ($requete == "") { Echo "alert('Aucune quarantaine n\\'a ete posee !');" ; }
     Echo "window.close();</script></body></html>" ;
     Exit ;
    }
   ElseIf ($requete == "AnNuLeR")
    {
     // Suppression de la quarantaine
     $ok = SQL_commande ("DELETE FROM abs_quarantaine WHERE id_abs_quarantaine='".$id."' LIMIT 1", $id_sql) ;
     Header ("location: ./abs_courrier.php?id_eleve=".$id_eleve) ;
     Exit ;
    }
  }

 Function formulaire_date ($j, $m, $a, $nj, $nm, $na)
  {
   Global $nom_mois ;
   $f = "<SELECT NAME=\"".$nj."\">" ;
   For ($k = 1 ; $k < 32 ; $k++)
    {
     $f .= "<OPTION VALUE=\"" ; If ($k < 10) { $f .= "0" ; }
     $f .= $k."\"" ;
     If ($k == $j) { $f .= " SELECTED" ; }
     $f .= ">".$k."</OPTION>" ;
    }
   $f .= "</SELECT>&nbsp;<SELECT NAME=\"".$nm."\">" ;
   For ($k = 1 ; $k < 13 ; $k++)
    {
     $f .= "<OPTION VALUE=\"" ; If ($k < 10) { $f .= "0" ; }
     $f .= $k."\"" ;
     If ($k == $m) { $f .= " SELECTED" ; }
     $f .= ">".$nom_mois [$k]."</OPTION>" ;
    }
   $f .= "</SELECT>&nbsp;<SELECT NAME=\"".$na."\">" ;
   For ($k = Date ("Y")-1 ; $k < Date ("Y")+2 ; $k++)
    {
     $f .= "<OPTION VALUE=\"" ; If ($k < 10) { $f .= "0" ; }
     $f .= $k."\"" ;
     If ($k == $a) { $f .= " SELECTED" ; }
     $f .= ">".$k."</OPTION>" ;
    }
   $f .= "</SELECT>" ;
   Return $f ;
  }
 
 $resultats = SQL_commande ("SELECT * FROM menus WHERE numero='".$droit_courant."' AND ordre='0'", $id_sql) ;
 $l = SQL_tableau_associatif ($resultats, "") ; 
 
 Echo "<HTML>" ;
 Echo "<HEAD>" ;
 entete_html ("Garennes - Module absences - Publipostage", "", 1) ;
 Echo styles ("none", "none", "none", $l ["lien"], "none") ;
 Include ("./abs_quarantaine.js") ;
 Echo "</HEAD>" ;
 
 // Recherche de l'eleve
 $resultats = SQL_commande ("SELECT * FROM eleves WHERE id_eleve='".$id_eleve."' LIMIT 1", $id_sql) ;
 $ligne = SQL_tableau_associatif ($resultats, "") ;
 
 Echo "<BODY BACKGROUND=\"../images/fond.png\" TEXT=\"#000000\">" ;
 Echo "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">" ;
 Echo "<TR>" ;
 Echo "<TD></TD>" ;
 Echo "<TD WIDTH=\"100%\" ALIGN=\"CENTER\"><FONT COLOR=\"#0000FF\">".$ligne ["nom"]."&nbsp;<I>".prenom_eleve ($ligne ["prenoms"])."</I></FONT></TD>" ;
 Echo "<TD><A onClick=\"javascript:window.close()\" BORDER=\"0\"><IMG SRC=\"../../images/quitter.png\" BORDER=\"0\" TITLE=\"Fermer la fen&ecirc;tre (pas de changement)\"></A></TD>" ;
 Echo "</TR>" ;
 Echo "</TABLE>" ;
 
 // Recherche de la quarantaine si existe
 $quarantaine = SQL_commande ("SELECT * FROM abs_quarantaine WHERE eleve='".$id_eleve."' AND repere1='".$ligne ["repere1"]."' AND repere2='".$ligne ["repere2"]."' LIMIT 1", $id_sql) ;
 $nombre = SQL_nbr_lignes ($quarantaine) ;
 If ($nombre == 1) { $q = SQL_tableau_associatif ($quarantaine, "") ; } Else { $q ["id_abs_quarantaine"] = 0 ; }
 
 Echo "<FORM ACTION=\"".$_SERVER ["PHP_SELF"]."\" NAME=\"abs_quarantaine\" METHOD=\"POST\">\n" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_eleve\" VALUE=\"".$id_eleve."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"repere1\" VALUE=\"".$ligne ["repere1"]."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"repere2\" VALUE=\"".$ligne ["repere2"]."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id\" VALUE=\"".$q ["id_abs_quarantaine"]."\">" ;
 Echo "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\">" ;
 Echo "<TR>" ;
 If ($nombre == 0) { Echo "<TD COLSPAN=\"5\" ALIGN=\"CENTER\">Mise en quarantaine</TD>" ; }
 Else { Echo "<TD COLSPAN=\"5\" ALIGN=\"CENTER\">Modification de la quarantaine</TD>" ; }
 
 Echo "<TR><TD COLSPAN=\"5\">&nbsp;</TD></TR>" ;
 
 If ($q ["date_debut"]) { $dd = Explode ("-", $q ["date_debut"]) ; } Else { $dd = Explode ("-", Date ("Y-m-d")) ; }
 Echo "<TR><TD ALIGN=\"RIGHT\" COLSPAN=\"2\">&Agrave;&nbsp;partir&nbsp;du&nbsp;</TD><TD ALIGN=\"LEFT\" COLSPAN=\"3\">".formulaire_date ($dd [2],$dd [1],$dd [0],"j1","m1","a1")."</TD></TR>" ;
 
 Echo "<TR><TD COLSPAN=\"5\">&nbsp;</TD></TR>" ;
 
 If ($q ["date_fin"]) { $df = Explode ("-", $q ["date_fin"]) ; } Else { $df = Explode ("-", Date ("Y-m-d")) ; }
 Echo "<TR><TD ALIGN=\"RIGHT\" COLSPAN=\"2\">jusqu'au&nbsp;</TD><TD ALIGN=\"LEFT\" COLSPAN=\"3\">".formulaire_date ($df [2],$df [1],$df [0],"j2","m2","a2")."</TD></TR>" ;
 
 Echo "<TR><TD COLSPAN=\"5\">&nbsp;</TD></TR>" ;
 Echo "<TR>" ;
 Echo "<TD COLSPAN=\"2\">&nbsp;</TD>" ;
 Echo "<TD ALIGN=\"CENTER\"><INPUT TYPE=\"IMAGE\" SRC=\"../images/absences/valider.png\" NAME=\"requete\" VALUE=\"VaLiDeR\" TITLE=\"Valider cette quarantaine et fermer la fen&ecirc;tre\"></TD>" ;
 Echo "</FORM>" ;
 If ($nombre == 1)
  {
   Echo "<FORM ACTION=\"".$_SERVER ["PHP_SELF"]."\" NAME=\"abs_quarantaine2\" METHOD=\"POST\" onSubmit=\"return valide()\">" ;
   Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_eleve\" VALUE=\"".$id_eleve."\">" ;
   Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id\" VALUE=\"".$q ["id_abs_quarantaine"]."\">" ;
   Echo "<TD ALIGN=\"CENTER\"><INPUT TYPE=\"IMAGE\" SRC=\"../images/absences/supprimer.png\" NAME=\"requete\" VALUE=\"AnNuLeR\" TITLE=\"Supprimer cette quarantaine et fermer la fen&ecirc;tre\"></TD>" ;
   Echo "</FORM>" ;
   Echo "<TD>&nbsp;</TD>" ;
  }
 Else { Echo "<TD COLSPAN=\"2\">&nbsp;</TD>" ; }
 Echo "</TR>" ;
 Echo "<TR><TD COLSPAN=\"2\">&nbsp;</TD>" ;
 Echo "<FORM ACTION=\"./abs_courrier.php\" NAME=\"annulation_quarantaine\" METHOD=\"POST\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"creation\" VALUE=\"".$creation."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"date_demande\" VALUE=\"".$date_demande."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_eleve\" VALUE=\"".$id_eleve."\">" ;
 Echo "<TD ALIGN=\"RIGHT\" COLSPAN=\"2\"><INPUT TYPE=\"IMAGE\" SRC=\"../images/absences/annuler.png\" NAME=\"annuler\" VALUE=\"AnNuLeR\" TITLE\"Annuler l'op&eacute;ration de mise en quarantaine...\">&nbsp;</TD>" ;
 Echo "</FORM>" ;
 Echo "</TR>" ;
 Echo "</TABLE>" ;
 Echo "</BODY>" ;
 Echo "</HTML>" ;
?>